//
//  TaskQueue.swift
//  TaskQueue
//
//  Created by TianChenIMac1 on 2019/12/6.
//  Copyright © 2019 skymesh. All rights reserved.
//

import UIKit

open class TaskQueue: OperationQueue {
    public func add(_ op: Operation) -> Self {
        addOperation(op)
        return self
    }
    
    @discardableResult
    public func start(_ startBlock: @escaping (TaskOperation) -> Void) -> Self {
        let start = TaskOperation(operationBlock: startBlock)
        addOperation(start)
        return self
    }
    
    @discardableResult
    public func then(_ thenBlock: @escaping (TaskOperation) -> Void) -> Self {
        let next = TaskOperation(operationBlock: thenBlock)
        if let last = operations.last {
            next.addDependency(last)
        }
        addOperation(next)
        return self
    }
}
